package com.cloudcc.mobile.manager;

import android.content.Context;

import com.cloudcc.cloudframe.CApplication;
import com.cloudcc.cloudframe.util.StringUtils;
import com.cloudcc.mobile.AppConfig;
import com.cloudcc.mobile.util.PreferenceUtils;
import com.mypage.bean.IsWebBean;

import static com.cloudcc.cloudframe.CApplication.isqunliao;
import static com.cloudcc.mobile.R.id.username;

/**
 * 应用程序运行时 产生的数据 用户注销的时候会清空
 * 
 * @Description: TODO()
 * @author wangzhiqiang
 * @date 2016-3-2 下午2:21:08
 * 
 */
public class RunTimeManager {

	private static RunTimeManager instance;

	private CApplication app;

	private final String XML = AppConfig.XML_APP;

	private RunTimeManager(Context app) {
		this.app = (CApplication) app;
	}

	public synchronized static RunTimeManager getInstance() {
		if (instance == null) {
			instance = new RunTimeManager(CApplication.getApp());
		}
		return instance;
	}

	/**
	 * 获取是否登录到了主页
	 */
	public boolean getGoHome(){
		return app.goHome;
	}

	public float setSale(float scale){
		return app.scale = scale;
	}
	/**
	 * 获取是否登录到了主页
	 */
	public boolean setGoHome(boolean gohome){
		return app.goHome = gohome;
	}

	/**
	 * 获得 服务器的binding
	 * 
	 * @return
	 */
	public String getServerBinding() {
		return StringUtils.isBlank(app.binding) ? StringUtils.EMPTY
				: CApplication.binding;
	}
	/**
	 * 获得 待审批数量
	 * 
	 * @return
	 */
	public String getDaiNum() {
		return StringUtils.isBlank(app.num) ? StringUtils.EMPTY
				: CApplication.num;
	}
	//baocun
	public boolean getIsBaocun() {
		return app.isbaocun;
	}

//公牛
public String getgongniu() {
	return app.gongniu;
}
	//baocun
	public boolean getIsQunLiao() {
		return isqunliao;
	}
	public float getScale(){
		return app.scale;
	}
	//baocun
	public boolean getIsRefreshx() {
		return app.IsRefreshx;
	}
	//同事的显示隐藏
	public String getTongshi() {
		return app.isTongshi;
	}
	//获取区域id
	public String getOrgId() {
		return StringUtils.isBlank(app.orgid) ? StringUtils.EMPTY
				: CApplication.orgid;
	}
	/**
	 * 获得 详情页是否刷新
	 * 
	 * @return
	 */
	public boolean getIsrem() {
		return app.isrem ;
	}
	//通知的消息数
	public long getMessageNx(){
		return app.messagenumxtz;
	}
	/**
	 * 设置 最后一次登录时间
	 * 
	 * @param time
	 */
	public void setLoginTime(long time) {
		((CApplication) CApplication.getApp()).lastLoginTime = time;
	}

	/**
	 * 获得最后一次登录的时间
	 * 
	 * @return
	 */
	public long getLastLoginTime() {
		return ((CApplication) CApplication.getApp()).lastLoginTime;
	}

	/**
	 * 设置会话binding
	 * 
	 * @param binding
	 */
	public static void setAppBinding(String binding) {
		CApplication.binding = binding;
	}
	//设置待审批数量
	public static void setDaiNum(String num) {
		CApplication.num = num;
	}
	//设置详情页是否刷新
		public static void setIsrem(Boolean isrem) {
			CApplication.isrem = isrem;
		}
	//用户id
	public static void setAppId(String id) {
		CApplication.Id = id;
	}
	//s是否保存联系人刷新
	public static void setIsbaocun(boolean isbaocun) {
		CApplication.isbaocun = isbaocun;
	}
	//s是否保存联系人刷新
	public static void setGongniu(String gongniu) {
		CApplication.gongniu = gongniu;
	}
	//消息数改变
	public static void setMessageNx(long messagenumxtz){
		CApplication.messagenumxtz = messagenumxtz;
	}
	public static void setIsQunLiao(boolean isqunliao) {
		CApplication.isqunliao = isqunliao;
	}
	public static void setIsRefreshx(boolean IsRefreshx) {
		CApplication.IsRefreshx = IsRefreshx;
	}
	/**
	* 设置会话language
	* @param binding
	*/ 
	public static void setAppLanguage(String language) {
		CApplication.language = language;
	}
    public static void setIsUsingGotpFlag(boolean bools){
    	CApplication.bools = bools;
    }
    
    public static void setIsBoundMfa(boolean bools){
    	CApplication.isBound = bools;
    }
    
	//角色
	public static void setJuese(String juese) {
		CApplication.juese = juese;
	}
	//id
	public static void setId(String id) {
		CApplication.Id = id;
	}
	public static void setUserId(String userId){
		CApplication.userId = userId;
	}
	public static void setUserName(String userName){
		CApplication.userName = userName;
	}
	public static void setorgId(String orgid){
		CApplication.orgid = orgid;
	}
	public static void setTongshi(String isTongshi){
		CApplication.isTongshi = isTongshi;
	}
	//建档
	public static void setJiandang(String jiandang) {
		CApplication.jiandang = jiandang;
	}
	//用户名
	public static void setLoginname(String loginname) {
		CApplication.loginname = loginname;
	}
	//version
		public static void setVersion(String version) {
			CApplication.version = version;
		}
	//获取建档用户名 角色 id
	public String getServerjiandang() {
		return StringUtils.isBlank(app.jiandang) ? StringUtils.EMPTY
				: CApplication.jiandang;
	}
	public String getServerjuese() {
		return StringUtils.isBlank(app.juese) ? StringUtils.EMPTY
				: CApplication.juese;
	}
	public String getServerloginname() {
		return StringUtils.isBlank(app.loginname) ? StringUtils.EMPTY
				: CApplication.loginname;
	}
	public String getId() {
		return StringUtils.isBlank(app.Id) ? StringUtils.EMPTY
				: CApplication.Id;
	}
	public String getUserId(){
		return StringUtils.isBlank(app.userId) ? StringUtils.EMPTY
				: CApplication.userId;
	}
	public String getUserName(){
		return StringUtils.isBlank(app.userName) ? StringUtils.EMPTY
				: CApplication.userName;
	}
	public String getVersion(){
		return StringUtils.isBlank(app.version) ? StringUtils.EMPTY
				: CApplication.version;
	}
	
	
	/**
	 * 设置动态类型
	 * 
	 * @param dynamicType
	 */
	public void setDynamicType(String dynamicType) {
		PreferenceUtils.commitString(app, XML, DYNAMIC_TYPE, dynamicType);
	}

	/**
	 * 获得动态类型
	 * 
	 * @return
	 */
	public String getDynamicType() {
		return PreferenceUtils.getString(app, XML, DYNAMIC_TYPE,
				AppConfig.DYNAMIC_TYPE);
	}

	private static final String MODEL_USER = "model.test";

	/**
	 * 获得是否是快速体验模式
	 * 
	 * @return
	 */
	public boolean isTestModel() {
		return PreferenceUtils.getBoolean(app, XML, MODEL_USER, false);
	}

	/**
	 * 设置是否是快速体验模式
	 * 
	 * @param isTest
	 */
	public void setTestModel(boolean isTest) {
		PreferenceUtils.commitBoolean(app, XML, MODEL_USER, isTest);
	}

	/**
	 * 保存的类型
	 */
	private static final String DYNAMIC_TYPE = "dynamic.type";

	/**
	 * 清空用户数据
	 */
	public void clearUserCache() {
		setAppBinding("");
		PreferenceUtils.clear(app, AppConfig.XML_VAR);
		PreferenceUtils.clear(app, XML);
	}

	public interface DynamicType {
		/**
		 * 我追随的内容
		 */
		String FOLLOW = "follow";

		/**
		 * 设计我的更新
		 */
		String ME = "me";

		/**
		 * 我收藏的微帖
		 */
		String MARK = "mark";

		/**
		 * 全部
		 */
		String COMPANY = "company";
		/**
		 * 我@出去的云帖
		 */
		String MYAT = "myat";
	}

	public String getlanguage() {
		return StringUtils.isBlank(app.language) ? StringUtils.EMPTY
				: CApplication.language;
	}
	public boolean getIsUsingGotpFlag(){
		 return CApplication.bools;
	}
	public boolean getIsBoundMfa(){
		return CApplication.isBound;
	}

	//权限ID
	public static void setProfileId(String profileId) {
		CApplication.profileId = profileId;
	}
	public String getProfileId(){
		return CApplication.profileId;
	}
}
